package com.base.engine.font;

import java.awt.Font;
import java.util.ArrayList;

import org.newdawn.slick.Color;


public final class MADFontManager {

	static class MADFontPackage { 
		private static int cnt = 0 ; 
		private int ID ; 
		private String name ; 
		private MADFont font; 
		private MADUnicodeFont uFont ; 
	
		public MADFontPackage(MADFont font){
			setID();
			setFont(font);
			setuFont(MADUnicodeFont.getUnicodeFontByMADFont(font));
		}
		

		public int getID() {
			return ID;
		}

		private void setID() {
			ID = cnt++;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			if(!(name == null) && !(name.equals("")))
				this.name = name;
		}

		public MADFont getFont() {
			return font;
		}

		public void setFont(MADFont font) {
			if(!(font == null)){
				this.font = font;
				setName(font.getName());
			}
		}

		public MADUnicodeFont getuFont() {
			return uFont;
		}

		public void setuFont(MADUnicodeFont uFont) {
			if(!(uFont == null))
				this.uFont = uFont;
		}	
	}
	
	public static final String DEFAULT = "Default"; 
	public static final String DEBUGGING_TEXT = "DebuggingText" ; 
	public static final String DEBUGGING_ERROR = "DebuggingError";
	public static final String MENU_TEXT = "MenuText"; 
	
	private static final MADFont DEFAULT_FONT = new MADFont("Lithos Pro", Font.BOLD, 18, Color.white, DEFAULT);
	private static final MADFont DEBUGGING_TEXT_FONT = new MADFont("Lithos Pro", Font.BOLD, 13, Color.white, DEBUGGING_TEXT);
	private static final MADFont DEBUGGING_ERROR_FONT = new MADFont("Lithos Pro", Font.BOLD, 13, Color.red, DEBUGGING_ERROR); 
	private static final MADFont MENU_TEXT_FONT = new MADFont("Lithos Pro", Font.BOLD, 16, Color.white, MENU_TEXT); 
	
	private static ArrayList<MADFontPackage> fonts = new ArrayList<MADFontPackage>(); 

	public static void init(){
		addFont(DEFAULT_FONT); 
		addFont(DEBUGGING_TEXT_FONT);
		addFont(DEBUGGING_ERROR_FONT);
		addFont(MENU_TEXT_FONT);
	}
	
	public static void addFont(MADFont font){
		if(!(font == null)){
			fonts.add(new MADFontPackage(font));
		}
	}
	
	public static MADFont getFontByName(String name){
		if(!(name == null) && !name.equals("")){
			for(MADFontPackage f: fonts){
				if(f.getName().equals(name))
					return f.getFont() ; 
			}
		}return DEFAULT_FONT ; 
	}
	
	public static MADFont getFontByID(int ID){
		if(ID>=0){
			for(MADFontPackage f: fonts){
				if(f.getID() == ID)
					return f.getFont() ; 
			}
		}return DEFAULT_FONT ; 
	}
	
	public static MADUnicodeFont getUFontByName(String name){
		if(!(name == null) && !name.equals("")){
			for(MADFontPackage f: fonts){
				if(f.getName().equals(name))
					return f.getuFont() ; 
			}
		}return toUnicodeFont(DEFAULT_FONT); 
	}
	
	public static MADUnicodeFont getUFontByID(int ID){
		if(ID>=0){
			for(MADFontPackage f: fonts){
				if(f.getID() == ID)
					return f.getuFont() ; 
			}
		}return toUnicodeFont(DEFAULT_FONT);
	}
	
	public static MADUnicodeFont toUnicodeFont(MADFont font){
		if(!(font == null))
			return MADUnicodeFont.getUnicodeFontByMADFont(font);
		return MADUnicodeFont.getUnicodeFontByMADFont(DEFAULT_FONT);
	}
	
	
	
	
}
